package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.bean.BannerBean;
import com.jjb.www.http.api.CertListApi;
import com.jjb.www.http.glide.GlideApp;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * Author: lkw
 * time:   2021/11/17 15:19
 * des:    电子准考证banner适配器
 */
public class BannerListAdapter extends BannerAdapter<CertListApi.Bean, BannerListAdapter.ImageTitleHolder> {

    private final Context mContext;

    public BannerListAdapter(Context context, List<CertListApi.Bean> datas) {
        super(datas);
        this.mContext = context;
    }

    @Override
    public ImageTitleHolder onCreateHolder(ViewGroup parent, int viewType) {
        return new ImageTitleHolder(LayoutInflater.from(mContext).inflate(R.layout.banner_image_title, parent, false));
    }

    @Override
    public void onBindView(ImageTitleHolder holder, CertListApi.Bean data, int position, int size) {
        holder.mTvTitle.setText(data.getCard_name());
        holder.mTvCertificateNumber.setText("证书编号："+data.getCert_num());
        holder.mTvCertificateTime.setText("到期时间："+data.getExpiry_date());
        GlideApp.with(mContext)
                .asBitmap()
                .load(data.getImg())
                .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners((int) mContext.getResources().getDimension(R.dimen.dp_4))))
                .into(holder.mImgHead);
    }

    public static class ImageTitleHolder extends RecyclerView.ViewHolder {
        private ShapeTextView mTvTitle;
        private ShapeImageView mImgHead;
        private ShapeTextView mTvCertificateNumber;
        private ShapeTextView mTvCertificateTime;




        public ImageTitleHolder(@NonNull View view) {
            super(view);
            mTvTitle = view.findViewById(R.id.tv_title);
            mImgHead = view.findViewById(R.id.img_head);
            mTvCertificateNumber = view.findViewById(R.id.tv_certificate_number);
            mTvCertificateTime = view.findViewById(R.id.tv_certificate_time);
        }
    }
}
